package com.ruoyi.web.controller.quality;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.quality.pojo.QualityInspection;
import com.ruoyi.quality.pojo.SalesVo;
import com.ruoyi.quality.service.QualityInspectionService;
import com.ruoyi.stock.mapper.WarehouseInInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 质检Controller
 *
 * @author ruoyi
 * @date 2024-10-25
 */
@RestController
@RequestMapping("/quality/inspection")
public class QualityInspectionController extends BaseController {
    @Autowired
    private QualityInspectionService qualityInspectionService;

    /**
     * 获取入库检列表
     */
    @PreAuthorize("@ss.hasPermi('quality:inspection:list')")
    @GetMapping("/getWarehouseInList")
    public TableDataInfo WarehouseInList(QualityInspection qualityInspection) {
        startPage();
        List<QualityInspection> list = qualityInspectionService.selectWarehouseInList(qualityInspection);
        return getDataTable(list);
    }

    /**
     * 获取出库检列表
     */
    @PreAuthorize("@ss.hasPermi('quality:inspection:list')")
    @GetMapping("/getWarehouseOutList")
    public TableDataInfo WarehouseOutList(QualityInspection qualityInspection) {
        startPage();
        List<QualityInspection> list = qualityInspectionService.selectWarehouseOutList(qualityInspection);
        return getDataTable(list);
    }

    /**
     * 获取销售出货订单产品列表
     */
    @PreAuthorize("@ss.hasPermi('quality:inspection:list')")
    @GetMapping("/salesList")
    public TableDataInfo salesList(SalesVo salesVo) {
        startPage();
        List<SalesVo> list = qualityInspectionService.salesList(salesVo);
        return getDataTable(list);
    }

    /**
     * 获取生产入库产品列表
     */
    @PreAuthorize("@ss.hasPermi('quality:inspection:list')")
    @GetMapping("/salesWorkList")
    public TableDataInfo salesWorkList(SalesVo salesVo) {
        startPage();
        List<SalesVo> list = qualityInspectionService.salesWorkList(salesVo);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('quality:inspection:list')")
    @GetMapping("/salesPurchaseList")
    public TableDataInfo salesPurchaseList(SalesVo salesVo) {
        startPage();
        List<SalesVo> list = qualityInspectionService.salesPurchaseList(salesVo);
        return getDataTable(list);
    }

    /**
     * 添加质检记录
     */
    @PreAuthorize("@ss.hasPermi('quality:inspection:add')")
    @Log(title = "质检", businessType = BusinessType.INSERT)
    @PostMapping("/addQuality")
    public AjaxResult add(@RequestBody QualityInspection qualityInspection) {
        qualityInspection.setUserId(getLoginUser().getUserId());
        qualityInspection.setQualityInspectionType(3);
        /*qualityInspection.setCreateBy(getUserId()+"");*/
        return toAjax(qualityInspectionService.insertQualityInspection(qualityInspection));
    }
}
